#define _CRT_SECURE_NO_WARNINGS
#include"List.h"
y* ListInit() {
	y* new = (y*)malloc(sizeof(y));
	new->data = NULL;
	new->next = new;
	new->prve = new;
	return new;
}
y* ListNewlyBuilt(x a) {
	y* new = (y*)malloc(sizeof(y));
	new->data = a;
	new->next = NULL;
	new->prve = NULL;
	return new;
}
void ListPrintf(y* phead) {
	y* new = phead->next;
	while (new!= phead) {
		printf("%d", new->data);
		new = new->next;
	}
}
void ListHeader(y* phead, x a)
{
	assert(phead);
	/*y* new = ListNewlyBuilt(a);
	y* newnode = phead->next;
	new->prve = phead;
	phead->next = new;
	new->next = newnode;
	newnode->prve = new;*/
	ListInsert(phead->next, a);
}

void ListTailPlugging(y* phead, x a) {
	assert(phead);
	/*y* newnode = phead->prve;
	y* new = ListNewlyBuilt(a);
	new->next = phead;
	phead->prve = new;
	newnode->next = new;
	new->prve = newnode;*/
	ListInsert(phead, a);
}
void ListHeaderDeleted(y* phead) {
	/*assert(phead);
	y* new = phead->next;
	y* newnode = new->next;
	phead->next = newnode;
	newnode->prve = phead;
	free(new);
	new = NULL;*/
	ListErase(phead->next);
}
void ListTailDeletion(y* phead) {
	assert(phead);
	/*y* new = phead->prve;
	y* newnode = new->prve;
	phead->prve = newnode;
	newnode->next = phead;
	free(new);
	new = NULL;*/
	ListErase(phead->prve);
}
y* ListFind(y* phead, x a) {
	assert(phead);
	y* new = phead->next;
	while (new!= phead) {
		if (new->data == a) {
			return new;
		}
		new = new->next;
	}
	return NULL;
}

void ListInsert(y* pos, x a) {
	assert(pos);
	y* new = ListNewlyBuilt(a);
	y* newnode = pos->prve;
	new->prve = newnode;
	newnode->next = new;
	pos->prve = new;
	new->next = pos;
	}
void ListErase(y* pos) {
	assert(pos);
	assert(pos->data != pos);
	y* new = pos->next;
	y* newnode = pos->prve;
	newnode->next = new;
	new->prve = newnode;
	free(pos);
	pos = NULL;
}
void Destroy(y* phead) {
	assert(phead);
	y* new = phead->next;
	while (new != phead) {
		y* l = new->next;
		free(new);
		new = NULL;
	}
	free(phead);
	phead = NULL;
}